package com.example.wacoffee_manage.Mapper;

import com.example.wacoffee_manage.annotation.AutoFill;
import com.example.wacoffee_manage.common.OperationType;
import com.example.wacoffee_manage.pojo.Employee;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    List<Employee> getAll(Employee employee);

    @AutoFill(OperationType.INSERT)
    void add(Employee employee);

    @Delete("delete from emp where id=#{id}")
    void delete(int id);

   @Select("select id, username, password, name, gender, phone, job, image, store_id from emp where id=#{id}")
    Employee getById(int id);

    @AutoFill(OperationType.UPDATE)
    @Update("update emp set  username=#{username},name=#{name},gender=#{gender},phone=#{phone},job=#{job},store_id=#{storeId},image=#{image},update_time=#{updateTime},updater=#{updater} where id=#{id}")
    void update(Employee employee);

    @Select("select id,username,password,name,gender,phone,job,image,store_id,create_time,update_time,creator,updater from emp where username=#{username} and password=#{password}")
    Employee getEmpByUsername(String username,String password);

    @Select("select id from emp where username=#{username} and password=#{oldPassword}")
    Integer getByUsernameAndPassword(String username, String oldPassword);

    @Update("update emp set password=#{newPassword} where id=#{id}")
    void updatePassword(Integer id, String newPassword);
}

